package com.chushouya.product.service.admin.impl;

import com.chushouya.product.dao.entity.EvaluateLogEntity;
import com.chushouya.product.dao.repository.EvaluateLogRepository;
import com.chushouya.product.dto.admin.evaluatelog.EvaluateLogListDTO;
import com.chushouya.product.dto.admin.evaluatelog.EvaluateLogQuery;
import com.chushouya.product.service.admin.EvaluateLogService;
import com.general.framework.core.lang.Jsons;
import com.general.framework.core.schema.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;

/**
 * 估价日志服务实现类
 */
@Service
@Slf4j
public class EvaluateLogServiceImpl implements EvaluateLogService {

    @Resource
    private EvaluateLogRepository evaluateLogRepository;

    @Override
    public PageResult<EvaluateLogListDTO> selectEvaluateLogPageResult(EvaluateLogQuery query) {
        PageResult<EvaluateLogEntity> pageResult = evaluateLogRepository.selectPageResult(query);
        PageResult<EvaluateLogListDTO> page = PageResult.of(pageResult, EvaluateLogListDTO.class);
        page.getRows().forEach(dto -> {
            dto.setEvaluateItemList(Jsons.parseArray(dto.getEvaluateItem(), Object.class));
        });
        return page;
    }
}
